/*添加默认样式*/
$("#scroller1 ul li").first().find(".sanjiao").css("display","block");
$("#scroller1 ul li").first().css("color","green");
sessionStorage.setItem("tid","0");

/*判断点击的科室不是当前的科室*/
for(i=0;i<$("#scroller1 ul li").length;i++){
	if($("#scroller1 ul li").eq(i).css("color")=="rgb(0, 128, 0)"){
		console.log($("#scroller1 ul li").eq(i).text());
		keshi=$("#scroller1 ul li").eq(i).text();
		sessionStorage.setItem("keshi",keshi);
	}
}
/*点击科室按钮的点击事件*/
$("#scroller1 ul").on("click","li",function(){
	var keshi="";
	$("#scroller1 ul li").css("color","#333");
	$(this).css("color","green");
	
	$("#scroller1 ul li span").css("display","none");
	$(this).find(".sanjiao").css("display","block");
	sessionStorage.setItem("tid",$(this).data("id"));
	if($(this).text()==sessionStorage.getItem("keshi")){
		console.log("不刷新");
	}else{
		num=1;
		sessionStorage.setItem("keshi",$(this).text());
		$("#add").html("");
		console.log("刷新");
		getList(num,"");
	}
})
/*$(".inner>ul>li").on("click",function(){
	$(".inner ul li").removeClass("click");
	$(".inner ul li b").css("display","none");
	if(!$(this).hasClass("click")){
		$(this).addClass("click");
		$(this).find("b").css("display","block");
	}
})*/

/*点击搜索框事件*/
$(".serch input").on("click",function(){
	var fenlei="";
	$(".lishi>ul").html("");
	$(this).css("width","90%");
	$(".serch b").css("right","0.6rem");
	$(".quxiao").css("display","block");
	$(".sousuo").css("display","block");
	/*获取热搜词*/
	$.ajax({
	    type: "post",
	    async: false,
	    url: url + "/index/hot_search"+"?area="+sessionStorage.getItem("area"),
	    datatype: "json",
	    success: function (data) {
			console.log(data);
			for(var i=0;i<data.length;i++){
				fenlei+='<li>'+data[i].field+'</li>';
			}
			$(".lishi>ul").append(fenlei);
	    }
	})
})
$(".quxiao").on("click",function(){
	$(".serch input").css("width","100%");
	$(this).css("display","none");
	$(".sousuo").css("display","none");
	$(".serch b").css("right","0.3rem");
})
/*点击热搜词中的某一项*/
var name="";
$(".lishi ul").on("click","li",function(){
	num=1;
	$(".serch input").css("width","100%");
	$(".sousuo").css("display","none");
	$(".serch b").css("right","0.3rem");
	
	/*取消科室的点中状态*/
	$("#scroller1 ul li").css("color","#333");
	$("#scroller1 ul li span").css("display","none");
	sessionStorage.setItem("keshi","无科室");
	
	$("#add").html("");
	name=$(this).html();
	var serch=$(this).html();
	sessionStorage.setItem("tid","");
	getList(num,name);
})



$(".sousuo>ul>li").on("click",function(){
	$(".sousuo>ul>li").removeClass("active");
	$(this).addClass("active");
	if($(this).html()=="最近搜索"){
		$(".lishi").css("display","block");
		$(".hot").css("display","none");
	}else{
		$(".lishi").css("display","none");
		$(".hot").css("display","block");
	}
})
/*预约弹窗*/
function tanchuang(event){
	/*点击预约以后把医生ID存session*/
	console.log($(event.target).parent().parent().data("did"));
	sessionStorage.setItem("did",$(event.target).parent().parent().data("did"));
	layer.open({
	  type: 2,
	  title: false,
	  shadeClose: false,
	  shade: 0.8,
	  area: ['auto', '80%'],
	  content: './form.html',//iframe的url
	  offset: '50px',
	  shift: 'left',
	  success: function (layero) {
      		$(layero).addClass("scroll-wrapper");              
	  }
	}); 
	
}

/*搜索按钮事件*/
$(".serch b").on("click",function(){
	num=1;
	$(".serch input").css("width","100%");
	$(".sousuo").css("display","none");
	$(this).css("right","0.3rem");
	$("#add").html("");
	
	/*取消科室的点中状态*/
	$("#scroller1 ul li").css("color","#333");
	$("#scroller1 ul li span").css("display","none");
	sessionStorage.setItem("keshi","无科室");
	
	name=$(".serch input").val();
	sessionStorage.setItem("tid","");
	getList(num,name);
})

console.log(url);
/*获取医生列表*/
function getList(num,name){
	var text="";
	$.ajax({
	    type: "post",
	    url: url + "/index/doctor_list",
	    data: "p="+num+"&lat="+lat+"&lng="+lng+"&tid="+sessionStorage.getItem("tid")+"&name="+name+"&area="+sessionStorage.getItem("area"),
	    datatype: "json",
	    success: function (data) {
	    	name="";
	    	console.log(name);
	    	console.log(data);
	    	for(var i=0;i<data.length;i++){
	    		text+='<li data-did="'+data[i].did+'">'+
	                        '<ul class="detail">'+
	                            '<li><img src="'+data[i].header+'"/></li>'+
	                            '<li>'+
	                                '<p>'+
	                                    '<span>'+data[i].name+'</span>'+
	                                '</p>'+
	                                '<p>'+data[i].title+'</p>'+
	                                '<p>'+data[i].address+'</p>'+
	                            '</li>'+
	                            '<li>'+data[i].intro+'</li>'+
	                        '</ul>'+
	                        '<div class="yuyue">'+
	                            '<span style="display:none;">以接诊'+data[i].reception_count+'人</span>'+
	                            '<span onclick="tanchuang(event)">挂号预约</span>'+
	                        '</div>'+
	                    '</li>';
	    	}
	    	//console.log(text);
	    	$("#add").append(text);
	    	myScroll.refresh();
	    },
	    error: function () {
	        
	    }
	});
}
